<?php
class Pedidof extends Controller {

    var $url="datacenter/pedidof/";

    function Pedidof(){
        parent::Controller();
        $this->load->library("rapyd");
//	$this->datasis->modulo_id('20D',1);
    }
    
    function index(){
        redirect($this->url.'filteredgrid');
    }
    
    function filteredgrid($numero=''){
        $this->rapyd->load('datafilter','datagrid');
        
        $atts = array(
                'width'      => '640',
                'height'     => '480',
                'scrollbars' => 'yes',
                'status'     => 'yes',
                'resizable'  => 'yes',
                'screenx'    => '0',
                'screeny'    => '0'
              );
        
        $filter = new DataFilter('');
        $filter->db->from("pedidof a");
        $filter->db->select(array('numero','a.barras','b.descrip','drogueria','SUM(cant) cant','costo','SUM(total) total','drolanca','dronena','cobeca'));
        $filter->db->join('viewsinvbarras b','a.barras=b.barras ');
        $filter->db->group_by('a.barras');
        if(!empty($numero))
        $filter->db->where('numero',$numero);
        else{
            $filter->numero = new inputField('Numero','numero');
            $filter->numero->size      =17;
            $filter->numero->maxlength =15;
        }
        
        
        $filter->barras = new inputField('Barras','barras');
        $filter->barras->size      =17;
        $filter->barras->maxlength =15;
        
        $filter->descrip = new inputField('Descripci&oacute;n','descrip');
        $filter->descrip->size      =17;
        $filter->descrip->maxlength =15;
        
        function drogueria($drogueria,$barras,$numero){
            $options = array(
                  'drolanca'  => 'Drolanca',   
                  'dronena'   => 'Dronena',     
                  'cobeca'    => 'Cobeca',
                );
                $js = 'id="C_'.$barras.'_'.$numero.'"';
                return form_dropdown('C_'.$barras.'_'.$numero, $options, $drogueria,$js);
        }
        
        $grid = new DataGrid('');
        $grid->use_function('drogueria');

        $grid->column_orderby('N&uacute;mero'     ,"numero"                                                         ,"numero"   ,'align="center"');
        $grid->column_orderby('barras'            ,"barras"                                                         ,"barras"   ,'align="center"');
        $grid->column_orderby('Descripci&oacute;n','descrip'                                                        ,"descrip"  ,'align="center"');
        $grid->column_orderby('Pedir a'           ,'<drogueria><#drogueria#>|<#barras#>|<#numero#></drogueria>'     ,"drogueria",'align="center"');
        $grid->column_orderby('Cantidad'          ,'cant'                                                           ,"cant"     ,'align="right"' );
        $grid->column_orderby('Costo'             ,'costo'                                                          ,"costo"    ,'align="right"' );
        $grid->column_orderby('Total'             ,'total'                                                          ,"total"    ,'align="right"' );
        $grid->column_orderby('Drolanca'          ,'drolanca'                                                       ,"drolanca" ,'align="right"' );
        $grid->column_orderby('Dronena'           ,'dronena'                                                        ,"dronena"  ,'align="right"' );
        $grid->column_orderby('Cobeca'            ,'cobeca'                                                         ,"cobeca"   ,'align="right"' );

        $grid->build();

        $data['filtro']  = $filter->output;
        $data['content'] = $grid->output;
        $data['head']    = $this->rapyd->get_head().script('jquery.js');
        $data['title']   = heading('Pedido');
        $this->load->view('view_ventanas', $data);
    }
    
    function creapedidof($numero){
        $this->db->query("CALL sp_creapedidof($numero)");
        redirect($this->url."filterdgrid/$numero");
    }
}
?>